Skip to content

Phase 2: smarter AI (router, filter-aware SQL, self-repair, streaming steps, eval) - #8

Merged
CodexManvik merged 8 commits into
mainfrom
phase2-smarter-ai
Nov 8, 2026
Merged

CodexManvik merged 8 commits into
mainfrom
phase2-smarter-ai

Conversation

@CodexManvik

Copy link
Copy Markdown
Owner

Phase 2 of the showcase plan: FloatChat now understands questions better, fixes its own SQL, and shows how it reached each answer.

What's new

  • Filter-aware SQL. Region, month, year and sensor filters now apply to the statistical answers too, not just to search. For example, "average temperature at different depths in the Arabian Sea" uses Arabian Sea data only. Filters are whitelisted (floatchat/filters.py) and always passed as bound parameters.
  • LLM router with a keyword fallback (floatchat/router.py). The LLM reads free phrasing and follow-ups ("now only the Bay of Bengal") and replies in JSON, which is validated. Keyword rules take over when the LLM is unavailable or its reply is unusable.
  • Self-correcting SQL. When the database rejects LLM-written SQL, the error goes back to the LLM for up to 2 repairs. If Groq returns a 429, the call is retried once, honouring Retry-After (waits capped at 10 s).
  • Glass-box answers. Every answer carries steps: what was understood, each SQL attempt, the search, and who wrote the text. The new POST /query/stream endpoint sends them as Server-Sent Events (step, token, result, error), ready for the Phase 3 web app.
  • Streamlit. The app sends the last 3 turns so follow-ups work, and each answer has a "How I answered" panel.
  • Evaluation suite (eval/). 30 benchmark questions, scored on routing, filters and answer checks, via python -m eval --api <url>. A weekly workflow runs it against the live API.

/query is backward compatible: history (request) and filters/steps (response) are optional additions.

Testing

  • 170 tests pass locally (unit tests, plus integration tests against Postgres + pgvector), and lint is clean.
  • After merge and the Render redeploy, I'll check the live API: a filtered depth average, a follow-up, streaming, and the eval score, which goes into the README.

🤖 Generated with Claude Code

CodexManvik and others added 8 commits November 8, 2026 22:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"Average temperature at different depths in the Arabian Sea" used to run a
whole-ocean template. Templates now join profiles and take the question's
region/month/year/sensor filters as bound parameters (regional comparisons
keep every region), and the answer title names the filters. Search and SQL
share one filter validator, so invalid values are dropped everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- floatchat/router.py: the LLM returns a JSON route (path, intent, filters,
  standalone question), validated against the known intents and filters;
  the keyword router takes over when there is no LLM or its reply is
  unusable, and resolves cue-word follow-ups ("now only the Arabian Sea")
- llm.chat: JSON mode, one retry on HTTP 429 honouring Retry-After (max 10 s)
- llm.chat_stream: yields the answer text as the LLM writes it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Custom SQL that fails is sent back to the LLM with the database's error
message, up to 2 repairs; each attempt is reported as a step. Filters are
passed to the LLM when it writes custom SQL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- answer_question routes through the LLM/keyword router, reports each step
  (understood, sql attempts, search, answer) and streams the answer text
- /query accepts up to 3 history turns for follow-ups and returns intent,
  filters and steps; follow-up answers are not cached
- POST /query/stream sends step, token and result events (Server-Sent
  Events); cached answers replay their steps; same rate limits as /query

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The chat now sends the last three answered turns so questions like "now only
the Arabian Sea" keep the earlier analysis, and every answer has a "How I
answered" expander listing the router decision, SQL attempts, search matches
and whether the LLM wrote the text. Example dates now match the rolling
12-month dataset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eval/questions.json holds 30 benchmark questions (every analysis, region,
month/year, sensor, descriptive search and follow-up). python -m eval --api
<url> asks them with rate-limit pacing and scores routing, filter accuracy and
answer checks (SQL rows that really apply the filters; searched profiles that
match them), writing eval/latest.md and eval/latest.json. A weekly workflow
runs it against the live API. The README documents Phase 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 8, 2026 17:43
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3615c994-e87a-4e87-bea0-4045ae317251
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@CodexManvik
CodexManvik merged commit aa90dd6 into main Nov 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants